import java.util.*;

public class SortList {

	/*
	 * Create method sort(List, boolean), which sort List with using parameter (Up and Down) and Comparator.
	 */
	public static void main(String[] args) 
	{
		List list = new ArrayList();

		Random a= new Random();
		for (int i=0;i<20;i++)
		{
			list.add(a.nextInt());
		}

		sort(list, true);
		System.out.println(Arrays.toString(list.toArray()));
		
		list = new ArrayList();
		for (int i=0;i<20;i++)
		{
			list.add(a.nextInt());
		}

		sort(list, false);
		System.out.println(Arrays.toString(list.toArray()));
	}

	static void sort(List list, final boolean updown) 
	{
		Comparator c = new Comparator() 
		{
			public int compare(Object o1, Object o2) 
			{
				boolean res=false;
				if ((Integer) o1 > (Integer) o2) res=true;
				if (!updown) res=!res;
				if (res)
				{
					return 1;
				}else {
					return -1;
				}
			}
		};
		Collections.sort(list, c);
	}
}
